package router

import (
	"github.com/gin-contrib/pprof"
	"github.com/gin-gonic/gin"
	"micro-server/middleware"
	"micro-server/router/routerInit"
	"micro-server/vender"
)

func InitRouter() *gin.Engine {

	router := gin.Default()
	pprof.Register(router)
	router.Use(middleware.Error)
	router.Use(middleware.CrossDomain())
	router.GET("/ping", func(c *gin.Context) {
		c.JSON(200, gin.H{
			"message": "pong",
		})
	})

	// 非登陆接口
	routerInit.ApiNormalGroup = router.Group("/micro")
	routerInit.ApiNormalGroup.Use(
		middleware.Recovery(),
		middleware.Log(),
		middleware.CheckVal(),
	)

	//
	vender.Init()

	return router
}
